//产品第三层
//引用insures集合模型
const { insuresModel } = require('./models/insuresModel')

//获取产品数据
module.exports.getInsures = async ({currentPage,pageSize}) => {
    const total = await insuresModel.countDocuments({delete:false})
    const page = Math.ceil(total / pageSize)
    
    const data = await insuresModel.find({ delete: false })
    //多表关联
    // .populate('typesId')
    .limit(pageSize-0)
    .skip( (currentPage-1) * pageSize)
    return {data,page,total}
}

//新增产品
module.exports.addInsures = async a => {
    const data = await insuresModel.create(a)
    
    return data;
}

//删除产品
module.exports.delInsures = async (a, b) => {
    const data = await insuresModel.updateOne(a, b)
    return data
}

//获取修改产品数据
module.exports.getInsuresById = async a => {
    const data = await insuresModel.find(a)
    // .populate(`typesId`)
    return data
}

//修改产品数据
module.exports.updateInsures = async a => {
    const data = await insuresModel.updateOne({ _id: a._id }, {
        name: a.name,
        payType: a.payType,
        suitableFor: a.suitableFor,
        renew: a.renew,
        policy: a.policy,
        price: a.price,
        // typesId:a.typesId
    })
    return data

}
